package com.ruoyi;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.framework.web.service.RedisService;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class Abc extends BaseTest {
    private static final Logger logger = LoggerFactory.getLogger(Abc.class);

    @Autowired
    RedisService redisService;
    /**使用RocketMq的生产者*/
    @Autowired
    private DefaultMQProducer defaultMQProducer;
    @Test
    public void test(){
        redisService.set("a","a",5l);
        String a = redisService.get("a");
        System.out.println("---a-----"+a);
        try {
            Thread.sleep(10000l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String b= redisService.get("a");
        System.out.println("----b----"+b);
    }

    @Test
    public void send() throws MQClientException, RemotingException, MQBrokerException, InterruptedException{
        SysUser sysUser = new SysUser();
        sysUser.setUserId(1L);
        sysUser.setLoginName("wangyun");
        sysUser.setUserName("王云");
        logger.info("开始发送消息："+sysUser.toString());
        Message sendMsg = new Message("yungee_test","userRegister",sysUser.toString().getBytes());
        //默认3秒超时
        SendResult sendResult = defaultMQProducer.send(sendMsg);
        logger.info("消息发送响应信息："+sendResult.toString());
    }

}
